package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("新增图书===");
        System.out.println("请输入书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int current = bookList.getUseSize();
        for (int i = 0; i < current; i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                System.out.println("该书已存在===");
                return;
            }
        }
        System.out.println("请输入作者：");
        String author = scanner.nextLine();
        System.out.println("请输入价格：");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入类型：");
        String type = scanner.nextLine();
        Book book = new Book(name,author,price,type);
        bookList.setBooks(current,book);
        bookList.setUseSize(current + 1);
        System.out.println("添加成功===");
    }
}
